package com.token.iot.bratterycharging.gateway.business;

import java.util.Map;

import org.springframework.stereotype.Component;

import com.outstanding.framework.core.PendingException;
import com.token.iot.bratterycharging.gateway.IDGeneration;
import com.token.iot.bratterycharging.gateway.api.ConsumptionAmount;
import com.token.iot.bratterycharging.gateway.api.Port;
import com.token.iot.bratterycharging.gateway.utils.ByteUtil;


/**
 * 查询消费总数据
 * @author chenzhixuan
 *
 */
@Component("DCBDuplexProcessor")
public class DCBDuplexProcessor extends DuplexProcessor {

	@Override
	public String request(String imei, Map<String, String> params) throws PendingException {
		String c = "DCB";
		String sessionId = IDGeneration.createSeesionID();
		String command = null;
		command = c + sessionId + "/";
		loger.info("the send =" + new String(command));
		byte[] cc = ByteUtil.addFlag(command.getBytes());
		context.writeAndFlush(cc);
		return sessionId;

	}

	@Override
	public ConsumptionAmount response(String response) throws PendingException {
		String val = response.substring(14);
		String[] params = val.split("#/#");
		ConsumptionAmount ca = new ConsumptionAmount();
		ca.setCardAmonut(params[0]);
		ca.setCoinAmonut(params[1]);
		return ca;

	}

}